package dao;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import pojo.Student;

import java.util.List;
import static tools.Dbutils.getSqlSession;
import static tools.Dbutils.logs;

public class TestOneToOne {
    /**
     *1.测试一对一
     */
    @Test
    public void findOneToOne() {
        logs();
        SqlSession sqlSession = getSqlSession();
        OrderDao mapper = sqlSession.getMapper(OrderDao.class);
        List oneToOne = mapper.findOneToOne();
        for (int i = 0; i < oneToOne.size(); i++) {
            System.out.println(oneToOne.get(i));
        }
    }

    /**
     * 2.测试一对多
     */
    @Test
    public void findOneToMore() {
        logs();
        SqlSession sqlSession = getSqlSession();
        OrderDao mapper = sqlSession.getMapper(OrderDao.class);
        List oneToMore = mapper.findOneToMore();
        for (int i = 0; i < oneToMore.size(); i++) {
            System.out.println(oneToMore.get(i));
        }
    }

    /**
     * 3.测试多对多
     */
    @Test
    public void findMoreToMore() {
        logs();
        SqlSession sqlSession = getSqlSession();
        OrderDao mapper = sqlSession.getMapper(OrderDao.class);
        List moreToMore = mapper.findMoreToMore();
        for (int i = 0; i < moreToMore.size(); i++) {
            System.out.println(moreToMore.get(i));
        }
    }

    /**
     * 4.测试三表联查
     */
    @Test
    public void ThreeTable() {
        logs();
        SqlSession sqlSession = getSqlSession();
        OrderDao mapper = sqlSession.getMapper(OrderDao.class);
        List<Student> students = mapper.threeTable();
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i));
        }
    }
}
